package com.jd.sunny.java.multithreading.concurrent.threadpool;

/**
 * @Description:ScheduledThreadPoolExecutor
 * @author:sunny
 * @since:2012-12-25 17:18
 * @version:1.0.0
 */

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 1.public interface ScheduledExecutorService extends ExecutorService
 * 2.public class ScheduledThreadPoolExecutor extends ThreadPoolExecutor implements ScheduledExecutorService
 *
 */
public class ScheduledExecutorServiceScheduledThreadPoolExecutorTest {


    public static void main(String[] args){
 
        //Creates a thread pool that can schedule commands to run after a
        //given delay, or to execute periodically.
        ScheduledExecutorService scheduledExecutorService =  Executors.newScheduledThreadPool(1);

        //new a ScheduledThreadPoolExecutor object 
        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);

        Runnable runnable = new Runnable() {
            public void run() {
                System.out.println("Thread is running ");
            }
        };

        /**
         * 1.executor at fixed time
         * 2.param : Runnable ,initialDelay,period,TimeUnit
         */

        scheduledThreadPoolExecutor.scheduleAtFixedRate(runnable,0,5, TimeUnit.SECONDS);
        
    }
}